<!DOCTYPE html>
<html>
	<head>
		{include file="top.tpl"}   		
		<link href="{$css.url}base_setting_min.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" type="text/css" href="{$css.url}zTreeStyle/tree.css">  
		<link rel="stylesheet" type="text/css" href="{$css.url}zTreeStyle/zTreeStyle.css"/>
		<link href='{$js.url}plugins/skin/layer.css' rel='stylesheet' type='text/css'/>
	    <link href="{$js.url}plugins/multiselect/css/bootstrap-multiselect.css" rel="stylesheet" type="text/css" />

        {literal}
        <style>
        	body{font-family: 'Microsoft yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif;padding: 0;}
			.saftyStock{display:none;}
			a{text-decoration: none;color: #333;}
			.h30{height: 30px;}
			.breadcrumb li{font-size: 14px;}
			.breadcrumb li a:hover,#sub_rule a:hover{background-color: transparent;}
			.my-form{padding: 0 10px;}
			.my-form table tr th{text-align:center; background-color:#eee;}
			#sub_rule a{color: #3c8dbc;text-decoration: underline;}
			#rule_layer table tr{line-height: 35px;}
			.ztree *{font-size: 13px!important;}
			.multiselect-container{position: relative;display: block;max-height: 1000px!important;min-width: 500px;max-width: 800px;overflow-y:hidden!important;}
			.multiselect-container li{width: 25%;display: inline-block;}
			.btn-group>.btn:first-child{margin-right: 5px;}
		</style>
		{/literal}
	</head>
<body>
{include file="bread_crumbs.tpl"}
<form id="rule-box" class="my-form" method="post" action="./save" name="theForm">
<table class="table-striped table-hover table-bordered" style="width: 100%;margin-top:5px; line-height:25px; font-size:14px;" id="stripe_tb">
	<tr>
    	<th colspan="2">&nbsp;新建备货规则</th>
  	</tr>
  	<tr bgcolor="#FFFFFF">
    	<td width="140" align="right" class="">规则名称：</td>
    	<td style="padding:8px;">
			<input type="text" id="rule_name" name="name" size="35"/><font style="font-size:12px; color:#666666;">（请使用通俗易懂的名称，如网采备货规则、非网采备货规则）</font>
		</td>
  	</tr>
  	<tr bgcolor="#FFFFFF">
    	<td align="right" class=" ">简单描述：</td>
    	<td style="padding:8px;">
			<textarea name="description" id="description" cols="80" rows="5"></textarea>
			<font style="font-size:12px; color:#666666;">（对此规则的简单描述）</font>
		</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right" class=" ">归类规则：</td>
    	<td style="padding:8px;">
			<a class="btn btn-primary btn-sm" href="javascript:show();"><span class="glyphicon glyphicon-plus"></span> 增加规则</a><br />
			<div id="sub_rule"></div>
		</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right" class="">平均销量计算公式：</td>
    	<td style="line-height:25px;padding:8px;">
			<input type="radio" name="avg_sales_formula_type" value="1" id="rdo_1" /><label for="rdo_1" class="ml5">公式1</label>(30天,15天,7天的平均销量分别为a,b,c,当c最大时,平均销量为c,当c非最大时,平均销量为0.4c+0.6b)<br />
			
			<input type="radio" name="avg_sales_formula_type" value="2" id="rdo_2" /><label for="rdo_2" class="ml5">公式2</label>(30天平均销量,当产品上架时间小于30天时,取上架时间段内的平均销量)<br />
			<input type="radio" name="avg_sales_formula_type" value="3" id="rdo_3" /><label for="rdo_3" class="ml5">公式3</label>((前15天销量*2+前7天销量*4.3)/60)<br />
			<input type="radio" name="avg_sales_formula_type" value="4" id="rdo_4" /><label for="rdo_4" class="ml5">公式4</label>
			(平均销量=前一周日均销量)【备货销量】<br />
			<input type="radio" name="avg_sales_formula_type" value="5" id="rdo_5" /><label for="rdo_5" class="ml5">公式5</label>			
			(平均销量=(前第一周销量*0.4+前第二周销量*0.6)/7)<br />
			<input type="radio" name="avg_sales_formula_type" value="6" id="rdo_6" /><label for="rdo_6" class="ml5">公式6</label>
			(平均销量=前一周日均销量)【真实销量】<br />
		</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right" class="">最小备货量：</td>
    	<td style="padding:8px;"><input type="text" size="14" value="" id="min_backup_qty" name="min_backup" />&nbsp;<span style="color:red; font-size:12px;">(当最终计算出来的需求C小于最小备货量时，不产生需求C即不备货)</span></td>
  	</tr>
  	<tr bgcolor="#FFFFFF">
    	<td align="right" class="">最大备货量：</td>
    	<td style="line-height: 35px;padding:8px;">
    		基数：
	    	<select class="h30" name='max_backup_base'>
	         	<option value='0'>请选择</option>
		    	
		        <option value='30'>前30天真实销量</option>
		        <option value='15'>前15天真实销量</option>
		        <option value='7'>前7天真实销量</option>

		        <option value='-30'>前30天备货销量</option>
		        <option value='-15'>前15天备货销量</option>
		        <option value='-7'>前7天备货销量</option>

		        <option value='1'>前7天备货销量</option>
	    	</select><br/>
    		系数：<input type="text" class="h30 ml5" size="14" value="" id="max_backup_x" name="max_backup_factor" />&nbsp;<span style="color:red; font-size:12px;"></span></td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right" class="">备货天数：</td>
    	<td style="padding:8px;">备货数量=平均销量*备货天数，备货天数=SUM(设置的条件得到的值)<br />
        SKU交期范围：<input name="backup_days_delivery_days_type" type="radio"  id="jiaoqi3" value="3" />
        不取交期 <input name="backup_days_delivery_days_type" type="radio" id="jiaoqi1" value="1" style="margin-left: 15px;" /> 取最小值  
        <input name="backup_days_delivery_days_type" type="radio" value="2"  id="jiaoqi2" style="margin-left: 15px;" /> 取最大值 <strong>+</strong> 质检天数：
        <input type="text" size="4" value="" id="quality_testing_days" name="backup_days_quality_testing_days" /> 
        <strong>+</strong>
        上架天数：<input type="text" size="4" value="" id="shelves_days" name="backup_days_shelves_days" /> <strong>+</strong>
        备货天数：<input type="text" size="4" value="" id="backup_days" name="backup_days_need_backup_days" /> </td>
  	</tr>
      <tr bgcolor="#FFFFFF">
    	<td align="right" class="">安全库存：</td>
    	<td style="padding:8px;">        
	        <input name="safe_stock_type" id="safety_stock_1" type="radio" value="1"  onclick="show_sub_type('saftyStock','ansales')" /> <label for="safety_stock_1">按销量</label>  <input name="safe_stock_type"  id="safety_stock_2" type="radio" style="margin-left: 15px;" value="2"  onclick="show_sub_type('saftyStock','andays')" />  <label for="safety_stock_2"> 按安全库存天数 </label>
	       
	       <div class="saftyStock" id="ansales_layer">
	           安全库存=基准*系数，请设置基准与系数：<br />
	           基数：
	    	<select name='safe_stock_base' class="h30">
	    	<option value='0'>请选择</option>

	        <option value='30'>前30天真实销量</option>
	        <option value='15'>前15天真实销量</option>
	        <option value='7'>前7天真实销量</option>

	        <option value='-30'>前30天备货销量</option>
	        <option value='-15'>前15天备货销量</option>
	        <option value='-7'>前7天备货销量</option>

	        <option value='1'>1</option>
	    	</select> 
	    	系数：<input type="text" size="14" value="" id="safety_stock_max_backup_x" name="safe_stock_factor" />&nbsp;<span style="color:red; font-size:12px;"></span>
	       </div>
		   <div class="saftyStock" id="andays_layer" > 
			        安全库存数量=<span style="color:#F00">平均销量</span>*安全库存天数，安全库存天数=SUM(设置的条件得到的值)
			        <br />
			        SKU交期范围：
			        <input name="safe_stock_delivery_days_type" id="safety_stock_jiaoqi_3" type="radio" value="3" style="margin-right: 5px;"/>不取交期  
			        <input name="safe_stock_delivery_days_type" id="safety_stock_jiaoqi_1" type="radio" value="1" style="margin-left: 15px;margin-right: 5px;" />取最小值  
			        <input name="safe_stock_delivery_days_type" id="safety_stock_jiaoqi_2" type="radio" value="2" style="margin-left: 15px;margin-right: 5px;" />取最大值 <strong>+</strong> 质检天数：
			        <input type="text" size="4" value="" id="safety_stock_quality_testing_days" name="safe_stock_quality_testing_days" /> 
			        <strong>+</strong>
			        上架天数：<input type="text" size="4" value="" id="safety_stock_shelves_days" name="safe_stock_shelves_days" /> <strong>+</strong>
			        备货天数：<input type="text" size="4" value="" id="safety_stock_backup_days" name="safe_stock_need_backup_days" />
	       </div>   
      </td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right" class="">是否启用：</td>
    	<td style="padding:8px;">
			<input type="radio" name="is_enable" value="2" id="rdo_enable_1" checked="checked" onclick="display_date(1)"/><label for="rdo_enable_1" class="ml5">停用</label>&nbsp;&nbsp;
			<input type="radio" name="is_enable" value="1" id="rdo_enable_2" onclick="display_date(2)"/><label for="rdo_enable_2" class="ml5 mr20">启用</label>
			<span style='display:none' id='date'>
			生效时间：
    		<input name="start_date" value="" id="start_date" class="Wdate date_start"  size="12" readonly=readonly/>
       		截止时间：
       		<input name="end_date" value="" id="end_date" class="Wdate date_start"  size="12" readonly=readonly/>
       		</span>
		</td>
  	</tr>
  	<tr bgcolor="#FFFFFF">
    	<td align="right" class="">优先级别：</td>
    	<td style="padding:8px;">
    	<select name='priority' class="h30" style='width:70px;'>
    	<option value='5'>5</option>
    	<option value='4'>4</option>
    	<option value='3'>3</option>
    	<option value='2'>2</option>
    	<option value='1'>1</option>
    	</select>
    	<span style='color:red;font-size: 12px;'>(优先级别从高到低顺序依次是1,2,3,4,5)</span>
    	</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
  	  <td align="right" style="vertical-align: middle;">适用仓库：</td>
  	   <td style="padding: 8px;">
          <select id="warehouseDepartment" class="h30" name="warehouse_department" style="vertical-align: top;">
          <option value="0">请选择事业部</option>
          </select>
          <span id="aaa">
          <select id="departmentWarehouse" multiple="multiple" class="" name="warehouse[]">
              <option>适用仓库</option>
          </select>
          </span>
       </td>
    </tr>    
    <tr bgcolor="#FFFFFF">
    	<td align="right" class=""> </td>
    	<td style="padding: 8px;color:#666666;">
			备注说明：<br />
			1.备货数量=平均销量*备货天数<br />
			2.需求C：当需求A大于0时，需求C等于备货数量，当需求A等于0时，需求C=备货数量－可用库存<br />
			3.需求C：当需求C小于最小备货量时，则不产生需求C
		</td>
  	</tr>
</table>
<div style="text-align: center;margin-top: 15px;">
	<input type="button" value="   确  定   " class="btn btn-default mr20" onclick="submitForm()" id="btnsubmit" />&nbsp;&nbsp;
	<input type="button" value="返回" class="btn btn-default" onclick="location.href='/backup/rule/list'" />
</div>
</form>

<div id="rule_layer" style="display:none;">
	<div style="padding:20px;font-size: 13px;">
		<table>
			<tr>
				<td width="80" align="left">筛选条件：</td>
				<td>
					<select id="type" name="type" class="h30" onchange="show_condition()">
					    <option value="product_level">产品等级</option>
						<option value="product_category">产品分类</option>
						<option value="product_sales">前30天历史销量</option>
						<option value="product_price">产品进货价</option>
						<option value="product_stock">库存</option>
						<option value="product_state">货源状态</option>
						<option value="recmd_level">产品推荐等级</option>
						<option value="chinabrands">chinabrands是否上架</option>
						<option value="live_age">产品生命周期</option>
					</select>
				</td>
			</tr>
			
			<tr>
				<td valign="top" align="left">条件设定：</td>
				<td>
					<div class="condition_layer" id="product_level_layer" style="padding:3px;">
						{foreach from=$allProductGrade item=productGrade }
							<li style="list-style:none;">
								<input type="checkbox" name="cbo_product_level" value="{$productGrade['id']}" id="cbo_level_{$productGrade['id']}" title="{$productGrade['name']}" /><label for="cbo_level_{$productGrade['id']}" class="ml5">{$productGrade['name']}</label>
							</li>
						{/foreach}
		
		
						<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitLevel()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="  取 消  " />
						</div>
					</div>
					
					<!--------------------------- 产品分类 ------------------------>
					<div class="condition_layer" id="product_category_layer" style="display:none;">
						<div>
							<ul id="all_product_category" class="ztree">
							</ul>
						</div>
						<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitCat()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="  取 消  " />
						</div>
					</div>
					
					<!--------------------------- 前30天历史销量 ------------------------>
					<div class="condition_layer" id="product_sales_layer" style="padding:3px; display:none;">
						<input type="radio" name="rdo_product_sales" id="rdo_sales_1" value="lt" onclick="show_sub_type('rproduct_sales_cls','sales_lt')" /><label for="rdo_sales_1" class="ml5">小于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_sales" id="rdo_sales_2" value="gt" onclick="show_sub_type('rproduct_sales_cls','sales_gt')" /><label for="rdo_sales_2" class="ml5">大于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_sales" id="rdo_sales_3" value="between" onclick="show_sub_type('rproduct_sales_cls','sales_in')" /><label for="rdo_sales_3" class="ml5">介于两个数量之间</label>
						<div class="rproduct_sales_cls" id="sales_lt_layer" style="display:none; line-height:25px;">
							前30天历史销量小于<input type="text" name="min_sales" id="min_sales" class="js_init" size="6" />个
						</div>
						<div class="rproduct_sales_cls" id="sales_gt_layer" style="display:none; line-height:25px;">
							前30天历史销量大于等于<input type="text" name="max_sales" id="max_sales" class="js_init" size="6" />个
						</div>
						<div class="rproduct_sales_cls" id="sales_in_layer" style="display:none; line-height:25px;">
							前30天历史销量介于<input type="text" name="in_min_sales" id="in_min_sales" class="js_init" size="6" />个(包含)
								<input type="text" name="in_max_sales" id="in_max_sales" class="js_init" size="6" />个(不包含)之间
						</div>
						
						<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitSales()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="  取 消  " />
						</div>
					</div>
					
					<!------------------------- 产品进货价 -------------------------->
					<div class="condition_layer" id="product_price_layer" style="padding:3px; display:none;">
						<input type="radio" name="rdo_product_price" id="rdo_price_1" value="lt" onclick="show_sub_type('product_price_cls','price_lt')" /><label for="rdo_price_1" class="ml5">小于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_price" id="rdo_price_2" value="gt" onclick="show_sub_type('product_price_cls','price_gt')" /><label for="rdo_price_2" class="ml5">大于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_price" id="rdo_price_3" value="between" onclick="show_sub_type('product_price_cls','price_in')" /><label for="rdo_price_3" class="ml5">介于两个数量之间</label>
						<div class="product_price_cls" id="price_lt_layer" style="display:none; line-height:25px;">
							产品进货价小于<input type="text" name="min_price" id="min_price" class="js_init" size="6" />元
						</div>
						<div class="product_price_cls" id="price_gt_layer" style="display:none; line-height:25px;">
							产品进货价大于等于<input type="text" name="max_price" id="max_price" class="js_init" size="6" />元
						</div>
						<div class="product_price_cls" id="price_in_layer" style="display:none; line-height:25px;">
							产品进货价介于<input type="text" name="in_min_price" id="in_min_price" class="js_init" size="6" />元(包含)
								<input type="text" name="in_max_price" id="in_max_price" class="js_init" size="6" />元(不包含)之间
						</div>
						<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitPrice()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="  取 消  " />
						</div>
					</div>
					
					<!--------------------------- 库存 ------------------------>
					<div class="condition_layer" id="product_stock_layer" style="padding:3px; display:none;">
						<input type="radio" name="rdo_product_stock" id="rdo_stock_1" value="lt" onclick="show_sub_type('product_stock_cls','stock_lt')" /><label for="rdo_stock_1" class="ml5">小于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_stock" id="rdo_stock_2" value="gt" onclick="show_sub_type('product_stock_cls','stock_gt')" /><label for="rdo_stock_2" class="ml5">大于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_stock" id="rdo_stock_3" value="between" onclick="show_sub_type('product_stock_cls','stock_in')" /><label for="rdo_stock_3" class="ml5">介于两个数量之间</label>
						<div class="product_stock_cls" id="stock_lt_layer" style="display:none; line-height:25px;">
							库存数量小于<input type="text" name="min_stock" id="min_stock" class="js_init" size="6" />个
						</div>
						<div class="product_stock_cls" id="stock_gt_layer" style="display:none; line-height:25px;">
							库存数量大于等于<input type="text" name="max_stock" id="max_stock" class="js_init" size="6" />个
						</div>
						<div class="product_stock_cls" id="stock_in_layer" style="display:none; line-height:25px;">
							库存数量介于<input type="text" name="in_min_stock" id="in_min_stock" class="js_init" size="6" />个(包含)
								<input type="text" name="in_max_stock" id="in_max_stock" class="js_init" size="6" />个(不包含)之间
						</div>
						
						<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitStock()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="  取 消  " />
						</div>
					</div>
					
					<!---------------------------货源状态------------------------>
					<div class="condition_layer" id="product_state_layer" style="padding:3px; display:none;">
						<input type="checkbox" name="cbo_product_state" id="cbo_state_1" value="1" title="正常" /><label for="cbo_state_1" class="ml5">正常</label>&emsp;
						<input type="checkbox" name="cbo_product_state" id="cbo_state_2" value="2" title="断货" /><label for="cbo_state_2" class="ml5">断货</label>&emsp;
						<input type="checkbox" name="cbo_product_state" id="cbo_state_3" value="3" title="停产" /><label for="cbo_state_3" class="ml5">停产</label>
						
						<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitState()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="  取 消  " />
						</div>
					</div>
					
					<!---------------------------推荐等级------------------------>
					<div class="condition_layer" id="recmd_level_layer" style="padding:3px; display:none;">
		
						<input type="checkbox" name="cbo_recmd_level" id="cbo_recmd_level_a" value="a" title="a" /><label for="" class="ml5">a</label>&emsp;
                        <input type="checkbox" name="cbo_recmd_level" id="cbo_recmd_level_b" value="b" title="b" /><label for="" class="ml5">b</label>&emsp;
						<input type="checkbox" name="cbo_recmd_level" id="cbo_recmd_level_c" value="c" title="c" /><label for="" class="ml5">c</label>&emsp;
						<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitRecmdLevel()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="  取 消  " />
						</div>
					</div>
					
					<!--------------------------CHINABRAND是否同步------------------------>
					<div class="condition_layer" id="chinabrands_layer" style="padding:3px; display:none;">
						<input type="checkbox" name="cbo_chinabrands" id="cbo_chinabrands_1" value="1" title="是" /><label for="cbo_chinabrands_1" class="ml5">是</label>&emsp;
						<input type="checkbox" name="cbo_chinabrands" id="cbo_chinabrands_2" value="0" title="否" /><label for="cbo_chinabrands_2" class="ml5">否</label>&emsp;
						
						<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitChinabrands()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="  取 消  " />
						</div>
					</div>
			
					<!-------------------------- 产品生命周期 ------------------------>
					<div class="condition_layer" id="live_age_layer" style="padding:3px; display:none;">
                    
                     <label for="live_age1"><input id="live_age1" name="live_age" type="checkbox" value="成长期" title="成长期" checked /> 成长期</label>
                     <label for="live_age2" class="ml10"><input id="live_age2" name="live_age" type="checkbox" value="成熟期" title="成熟期" checked /> 成熟期</label>
                     <label for="live_age3" class="ml10"><input id="live_age3" name="live_age" type="checkbox" value="衰败期" title="衰败期" checked /> 衰败期</label>
                     <label for="live_age4" class="ml10"><input id="live_age4" name="live_age" type="checkbox" value="其他时期" title="其他时期" checked /> 其他时期</label>
      					<div class="mt20 mb20">
							<input type="button" class="btn btn-default mr15" value="  确 定  " onclick="toSubmitLiveAge()" />
							<input type="button" class="btn_cancel_cls btn btn-default" value="返回" />
						</div>           
                    </div>
				</td>
			</tr>
		</table>
	</div>
</div>
{include file='foot.tpl'}
<script src="{$js.url}backup/backup_rule.js"></script>
<script src="{$js.url}app_widget/product_catalog.js"></script>
<script src="{$js.url}app_widget/warehouse.js"></script>

<script src="{$js.url}plugins/multiselect/js/bootstrap-multiselect.js"></script>
<script>
{literal}
var productCatalog=new AppProductCatalog("all_product_category");
productCatalog.init();

$(function(){
	$('.date_start').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	}).on('changeDate', function(ev){
        $(".date_end").val("").datetimepicker('setStartDate',$(this).val());
    });
    $('.date_end').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	});
})

function display_date(val)
{
	if(val==1)
	{
	    document.getElementById('date').style.display='none';	
	}else if(val==2){
		document.getElementById('date').style.display='';
	}
}
{/literal}

depWarehouse=new DepartmentWarehouse("warehouseDepartment","departmentWarehouse",true);
depWarehouse.initDep();
depWarehouse.init();

</script>
</body>
</html>